import request from "../../utils/request";

let startY = 0;
let moveY = 0;
let moveDistance = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coverTransform: 'translateY(0)',
    coverTransition: '',
    userInfo: {},
    userPlayRecordList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let userInfo = wx.getStorageSync('userInfo')
    // console.log(userInfo)
    this.setData({
      userInfo: JSON.parse(userInfo)
    })

    // 获取用户播放记录数据
    this.getUserPlayRecordList(this.data.userInfo.userId)

  },

  async getUserPlayRecordList(uid) {
    let userPlayRecordData = await request("/user/record",{uid: uid,type: 0})
    console.log("userPlayRecordData",userPlayRecordData)
    let index = 0
    this.setData({
      userPlayRecordList: userPlayRecordData.allData.slice(0,10).map(item => {
        item.id = index++
        return item
      })
    })
  },

  handleTouchStart(event) {
    this.setData({
      coverTransition: ''
    })
    // 获取触摸起始点的Y坐标
    startY = event.touches[0].clientY
  },
  handleTouchMove(event) {
    moveY = event.touches[0].clientY
    moveDistance = moveY - startY

    if (moveDistance < 0) {
      return;
    }

    if (moveDistance >= 70) {
      moveDistance = 70;
    }

    this.setData({
      coverTransform: `translateY(${moveDistance}px)`
    })
  },
  handleTouchEnd() {
    this.setData({
      coverTransform: `translateY(0)`,
      coverTransition: 'transform 1s linear'
    })
  },

  toLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})
